package vn.allmobile.ambnews;


import vn.allmobile.ambnews.customview.LoadingDialog;
import vn.allmobile.ambnews.data.DbFeedAdapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class ToolsActivity extends Activity {
	ProgressDialog dialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_ACTION_BAR);
		setContentView(R.layout.activity_tools);
		
		TextView txt_desc = (TextView)findViewById(R.id.txt_desc);
		txt_desc.setText(Html.fromHtml(getString(R.string.tools_desc)));
		Button btn_delete = (Button)findViewById(R.id.btn_delete);
		
		btn_delete.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View v) {
				 alertMessage();
				
			}
		});
	}

	public void alertMessage() { 
		DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() 
		{ 
			public void onClick(DialogInterface dialog, int which)
			{ 
				switch (which) 
				{
					case DialogInterface.BUTTON_POSITIVE: 
						dialog = ProgressDialog.show(ToolsActivity.this,"Xóa dữ liệu","Đang xử lý...", true);
						DbFeedAdapter.deleteOldAritlce();
						Toast.makeText(ToolsActivity.this, "Đã xóa dữ liệu cũ.", Toast.LENGTH_SHORT).show();
						dialog.dismiss();
						break; 
					case DialogInterface.BUTTON_NEGATIVE:
						
						break;
				} 
			} 
		};
		AlertDialog.Builder builder = new AlertDialog.Builder(this); 
		builder.setMessage("Bạn có chắc muốn xóa dữ liệu không?") 
		.setPositiveButton("Có", dialogClickListener) 
		.setNegativeButton("Không", dialogClickListener).show(); 
	}
		

}
